﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using CoreModel = PlayerScannerCore.Model;
using Mvvm;
using PlayerScannerCore.Model;

namespace PlayerScannerCore.ViewModel
{
    public class ItemViewModel : ViewModelBase, IItem
    {
        private uint _id;
        private string _name;
        private ItemType _itemType;
        private bool _isEquipped;
        private string _description;

        internal ItemViewModel()
        {
            ItemType = ItemType.Unknown;
        }

        internal virtual void Update(IItem item)
        {
            Id = item.Id;
            ItemName = item.ItemName;
            IsEquipped = item.IsEquipped;
            Description = item.Description;
        }

        public uint Id
        {
            get { return _id; }
            set
            {
                if (_id != value)
                {
                    _id = value;
                    OnPropertyChanged("Id");
                }
            }
        }

        public bool IsEquipped
        {
            get { return _isEquipped; }
            set
            {
                if (_isEquipped != value)
                {
                    _isEquipped = value;
                    OnPropertyChanged("IsEquipped");
                }
            }
        }

        public ItemType ItemType
        {
            get { return _itemType; }
            set
            {
                if (_itemType != value)
                {
                    _itemType = value;
                    OnPropertyChanged("ItemType");
                }
            }
        }

        public string ItemName
        {
            get { return _name; }
            set
            {
                if (_name != value)
                {
                    _name = value;
                    OnPropertyChanged("ItemName");
                }
            }
        }

        public string Description
        {
            get { return _description; }
            set
            {
                if (_description != value)
                {
                    _description = value;
                    OnPropertyChanged("Description");
                }
            }
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int hash = 23;
                hash = hash * 29 + Id.GetHashCode();
                hash = hash * 29 + ItemName.GetHashCode();
                hash = hash * 29 + ItemType.GetHashCode();
                hash = hash * 29 + IsEquipped.GetHashCode();
                hash = hash * 29 + Description.GetHashCode();
                return hash;
            }
        }

        public override bool Equals(object obj)
        {
            var objAsItemViewModel = obj as ItemViewModel;
            if (objAsItemViewModel == null)
                return false;

            if (ReferenceEquals(this, obj))
                return true;

            return objAsItemViewModel.Id == Id
                && objAsItemViewModel.ItemName == ItemName
                && objAsItemViewModel.ItemType == ItemType
                && objAsItemViewModel.IsEquipped == IsEquipped
                && objAsItemViewModel.Description == Description;
        }
    }
}
